<template>
  <view class="container">
    <view class="success-icon">
      <text class="icon">✓</text>
    </view>

    <view class="success-info">
      <text class="title">下单成功</text>
      <text class="desc">您的订单已提交，商家正在处理中</text>
    </view>

    <view class="order-info">
      <view class="info-item">
        <text class="label">订单编号</text>
        <view class="value-copy">
          <text class="value">{{ orderId }}</text>
          <text class="copy-btn" @click="copyOrderId">复制</text>
        </view>
      </view>
    </view>

    <view class="buttons">
      <button class="btn primary" @click="goToOrderDetail">查看订单</button>
      <button class="btn" @click="goToIndex">返回首页</button>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'

// 响应式状态
const orderId = ref('')

/**
 * 复制订单ID到剪贴板
 */
const copyOrderId = () => {
  uni.setClipboardData({
    data: orderId.value,
    success: () => {
      uni.showToast({
        title: '复制成功',
        icon: 'success'
      })
    }
  })
}

/**
 * 跳转到订单详情页
 */
const goToOrderDetail = () => {
  uni.redirectTo({
    url: `/pages/order/detail?id=${orderId.value}`
  })
}

/**
 * 返回首页
 */
const goToIndex = () => {
  uni.switchTab({
    url: '/pages/index/index'
  })
}

// 获取页面参数
onLoad((options) => {
  console.log("onLoad options===", options)
  orderId.value = options?.id || ''
})
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background: #f0f2f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 100rpx 40rpx;
}

.success-icon {
  width: 160rpx;
  height: 160rpx;
  background: #52c41a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 40rpx;
  box-shadow: 0 8rpx 30rpx rgba(82, 196, 26, 0.3);
  animation: scaleIn 0.5s ease-out;
}

@keyframes scaleIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  60% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.icon {
  color: #fff;
  font-size: 80rpx;
  font-weight: bold;
  text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
}

.success-info {
  text-align: center;
  margin-bottom: 60rpx;
  animation: fadeInUp 0.5s ease-out 0.3s both;
}

@keyframes fadeInUp {
  from {
    transform: translateY(20rpx);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.title {
  font-size: 40rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  display: block;
  background: linear-gradient(135deg, #333, #666);
  -webkit-background-clip: text;
  color: transparent;
}

.desc {
  font-size: 28rpx;
  color: #666;
}

.order-info {
  width: 100%;
  background: #ffffff;
  border-radius: 20rpx;
  padding: 30rpx;
  margin-bottom: 60rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
  animation: fadeInUp 0.5s ease-out 0.6s both;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label {
  font-size: 28rpx;
  color: #666;
}

.value-copy {
  display: flex;
  align-items: center;
  gap: 20rpx;
}

.value {
  font-size: 28rpx;
  color: #333;
  font-family: monospace;
}

.copy-btn {
  font-size: 24rpx;
  color: #ff4d4f;
  background: #fff1f0;
  padding: 6rpx 16rpx;
  border-radius: 20rpx;
  border: 1rpx solid #ffccc7;
  transition: all 0.3s;
}

.copy-btn:active {
  transform: scale(0.95);
  background: #ffd6d6;
}

.buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20rpx;
  animation: fadeInUp 0.5s ease-out 0.9s both;
}

.btn {
  width: 100%;
  height: 80rpx;
  border-radius: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30rpx;
  font-weight: bold;
  transition: all 0.3s;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: #ff4d4f;
  color: #fff;
  box-shadow: 0 4rpx 12rpx rgba(255, 77, 79, 0.3);
}

.btn:not(.primary) {
  background: #ffffff;
  color: #666;
  border: 2rpx solid #f0f0f0;
}
</style>